package com.dhcc.sds.busi.controller;


import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.sys.cache.config.CdcConfigCache;
import com.dhcc.cdc.sys.entity.ConfigurationEntity;
import com.dhcc.cdc.sys.service.IConfigurationService;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.sds.busi.entity.SdsQcincaseEntity;
import com.dhcc.sds.busi.service.ISdsFillByDoctorService;
import com.dhcc.sds.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 病种入组病例
 * 
 * @ClassName: SdsFillByDoctorController
 * @Description: TODO
 * @author sunyingjie
 * @date 2021-03-22 10:09:15
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdsfillbydoctor")
public class SdsFillByDoctorController extends BaseController {

	private String PREFIX = "/backend/sds/sdsfillbydoctor/";

	@Autowired
	private ISdsFillByDoctorService sdsFillByDoctorService;

    @Autowired
    private IConfigurationService configurationService;
	

    /**
     * 跳转到病种入组病例列表首页
     */
    @RequestMapping("")
    public String index(Model model) {

        DateTime lastDay = new DateTime();
        DateTime firstday = DateUtil.getDateByDay(lastDay, -10);

        model.addAttribute("startDate", firstday);
        model.addAttribute("endDate", lastDay);
        // 单病种医生是否可以直接上报配置
        String formCheckType = CdcConfigCache.me().getValueByKey("SDS", "SDFormCheckType");
        JSONObject statusMap = sdsFillByDoctorService.getStatusMapByType("SDQCMrStatus");
        model.addAttribute("formCheckType", formCheckType);
        model.addAttribute("statusMap", statusMap);

        return PREFIX + "sdsfillbydoctor.html";
    }

    /**
     * 获取病种入组病例列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdsQcincaseEntity> page = new PageFactory<SdsQcincaseEntity>().defaultPage();
        List<SdsQcincaseEntity> result = this.sdsFillByDoctorService.page(page,params);
        page.setRecords((List<SdsQcincaseEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 获取质控病种字典列表(不分页)
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/qryQCEntity")
    @ResponseBody
    public Object qryQCEntity(@RequestParam Map<String, Object> params) {
        return this.sdsFillByDoctorService.listByDate(params);
    }
	
}
